<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/style.css" />
<title>Admin control panel !</title>
</head>

<body>
<?php include("menu.php"); 
include("../include/config.php");
?>

<div id="head-noidung">
	<div id="head-main">
		
	<form name="addcategory" method="get">
	
	<table class="classtable" style="width:45%;">
	<tbody">
	<tr>
	<td>Tên chuyên mục con</td>
	<td><input name="subcategory" type="text" size="35" style="float:left;"></td>
	</tr>
	
	<tr>
	<td>Số thứ tự</td>
	<td><input name="stt" type="text" size="5" style="float:left;"></td>
	</tr>
	<tr>
		<td>Trạng thái</td>
		<td>
			<select name="status">
				<option value="1"> Hiện </option>
				<option value="0"> Ẩn </option>
			</select>
		</td>
	</tr>
	<tr>
	<td>Chuyên mục (*)</td>
	<td>
	
	<select name="category_id">
	<option value="0"> Lựa chọn</option>
	<?php 
	$sql2="SELECT * FROM category ORDER BY stt";
	$rs2=mysql_query($sql2);
	if($rs2) {
		while($rw2=mysql_fetch_array($rs2)) {
		?>	<option value="<?php echo $rw2["id"]?>"> <?php echo $rw2['name']?></option>
		<?php
		}
	}
	
	?>
	
</select>
	
	</td>
	<tr>
	<td></td>
	<td><input type="submit" name="addsubcategory" value="Thêm mới" /></td>
	</tr>
	
	
	</tbody>
	</table>
	</form>
	
<?php 

if(isset($_GET['addsubcategory'])) 
	{  	$name=$_REQUEST["subcategory"];
		$stt = (int)$_REQUEST["stt"];
		$status = (int)$_REQUEST["status"];
		$category_id = (int)$_REQUEST["category_id"];
		$sql = "INSERT INTO subcategory(name, stt, parent_id, status) VALUES('" . addslashes($name) . "',$stt,$category_id,$status)";
		$result = mysql_query($sql);
		if($result){
		echo "Đã tạo chuyên mục thành công !";
		echo "<br><a href='category.php'>Tiếp tục</a>";
		}
	}	

?>	
		
	</div>	
</div>

<?php include("images/cherry/footer.php"); ?>

</body>
</html>
